<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>面向对象封装消息提示</title>
  <style>
    .modal {
      width: 300px;
      min-height: 100px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
      border-radius: 4px;
      position: fixed;
      z-index: 999;
      left: 50%;
      top: 50%;
      transform: translate3d(-50%, -50%, 0);
      background-color: #fff;
    }

    .modal .header {
      line-height: 40px;
      padding: 0 10px;
      position: relative;
      font-size: 20px;
    }

    .modal .header i {
      font-style: normal;
      color: #999;
      position: absolute;
      right: 15px;
      top: -2px;
      cursor: pointer;
    }

    .modal .body {
      text-align: center;
      padding: 10px;
    }

    .modal .footer {
      display: flex;
      justify-content: flex-end;
      padding: 10px;
    }

    .modal .footer a {
      padding: 3px 8px;
      background: #ccc;
      text-decoration: none;
      color: #fff;
      border-radius: 2px;
      margin-right: 10px;
      font-size: 14px;
    }
    .modal .footer a.submit {
      background-color: #369;
    }
  </style>
</head>

<body>
    <button id="delete">删除</button>
    <button id="login">登录</button>
    <!--
        <div class="modal">
            <div class="header">温馨提示</div>
            <div class="body">您没有删除权限操作</div>
        </div> 
    -->
  <script>
      
      // 1. 找对象 (提示框)
      // 2. 属性 +  方法
      function MsgBox(title, content) {
            this.title = title;
            this.content = content;
            this.Box = document.createElement('div');
            this.Box.className = 'modal';
            this.Box.innerHTML = 
                ` <div class="header">${this.title}</div>
                  <div class="body">${this.content}</div>`;
      }
      
      // 3. 给构造函数设置添加div标签的方法
      MsgBox.prototype.add = function() {
           // 延迟函数,将div标签隐藏
           setTimeout(()=> {
              // this.Box.style.display = 'none';

              document.body.removeChild(this.Box);
           }, 2000)

           // 将创建的div追加到页面中
           document.body.appendChild(this.Box);
      }

      // 4. 实现功能
      let del_btn = document.querySelector('#delete');

      del_btn.addEventListener('click', function() {
           // 创建提示框盒子对象
           let divbox = new MsgBox('删除提示信息', '没有权限删除');
           // 调用add方法
           divbox.add();
      });

      let btn = document.querySelector('#login');
      btn.addEventListener('click', function() {
          let divbox = new MsgBox('登录提示信息', '还没有注册');
          divbox.add();
      })





        
     

  </script>
</body>

</html>